<template>
  <div class="app-container">
    <el-row :gutter="20">
      <el-col :span="20" :xs="24" style="width: 100%;">
        <el-form :model="queryParams" ref="msgFrom" :inline="true" v-show="true" label-width="68px" prop="msgFrom">
          <el-form-item label="用户账号" prop="user_account">
            <el-input
              v-model="queryParams.user_account"
              placeholder="请输入用户账号"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item label="时间">
            <el-date-picker
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>


        <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="用户ID" align="center" key="user_id" prop="user_id"  />
          <el-table-column label="积分" align="center" key="mark" prop="mark"  :show-overflow-tooltip="true" />
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="GetList"
        />
      </el-col>
    </el-row>

  </div>
</template>

<script>
  import { userMarkType ,userMark } from "@/api/system/user";
  import { getToken } from "@/utils/auth";

  export default {
    name: "Msg",
    data() {
      return {
        flag: [],
        /*消息类型*/
        msgType:[
          {
            id: 'LOGIN',
            label: '登录'
          },
          {
            id: 'BIRTHDAY',
            label: '生日'
          },
          {
            id: 'MARK',
            label: '用户积分'
          },
          {
            id: 'USER_LEVEL',
            label: '用户等级'
          },
        ],
        /*表格数据*/
        list:[],
        // 总条数
        total: 0,
        // 日期范围
        dateRange: [],
        // 用户导入参数
        upload: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "",
          // 遮罩层
          loading: true,
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
        },
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name: "",
          subscription:undefined,
          type:undefined,
          read_flag:undefined
        },
      };
    },
    watch: {

    },
    created() {
      this.GetList();
    },

    methods: {

      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.page = 1;
        this.GetList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.dateRange = [];
        this.resetForm('msgFrom');
        this.handleQuery();
      },


      /*获取用户消息列表*/
      GetList(){
        this.loading = true;
        console.log('loading...')
        userMark(this.addDateRange(this.queryParams, this.dateRange)).then(response=>{
          console.log(response.data)
          this.list= response.data.items;
          this.total = response.data.total;
          this.loading = false;
        })
      },

      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.user_id);
        this.single = selection.length != 1;
        this.multiple = !selection.length;
      },
    },

  };
</script>
